Wyo Java Ch20Proj1

Write a class named Ch20Proj1 that contains the following static methods.

public static Set<String> union(Set<String> set1, Set<String> set2)
public static Set<String> intersection(Set<String> set1, Set<String> set2)
public static Set<String> difference(Set<String> set1, Set<String> set2)
public static boolean isASubset(Set<String> superset, Set<String> subset)

In this assignment, you must use HashSets however the Set reference type is used above so that the same methods could also be used with TreeSets.

  • The union method must merge all of the elements of its two parameters into one set that is returned.
  • The intersection method returns a set that is created from all of the elements that are in both of its parameter sets.
  • The difference method combines all of the elements in set1 that are not in set2 with all of the elements that are in set2 but are not in set1 and returns that resulting set.
  • The isASubset method determines if the parameter subset is a subset of the parameter superset and returns a true if it is and false otherwise.

None of the methods above may change the parameters passed to them. Write the client program so that set1 and set2 are created as the set of all words in two text files named set1.txt and set2.txt where the words are typed on separate lines. Use Scanner for file input.

Be sure to execute code that makes the program easy to grade (i.e. print out the contents of the sets where necessary to show that the algorithms work correctly.) Your program must follow the class Coding Standards. Save all of the files associated with this assignment to a folder named Ch20Proj1 in the appropriate network folder.

Submit the printed code stapled to a screen capture of the runtime output as well as copies of set1.txt and set2.txt.

You must hand in the following on separate pages stapled in this specified order:

    1. The source code for the Ch20Proj1 class
    2. The printscreen of your output
    3. set1.txt
    4. set2.txt